package com.wontube.client.modle.vo;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

import com.wontube.client.pub.RequestHeaders;

/**
 * @author yuechao
 *
 */
public class ClientSession implements Serializable {
	private static final long serialVersionUID = -7147231726325434650L;

	private String sessionId;
	private String lastAgent;
	private Date lastAccessTime;
	private String lastAccessIntf;
	private String lastAccessMethod;
	private String lastClientIP;
	private String lastAPIVersion;
	private String lastDataFormat;

	private HashMap<String, Object> map = new HashMap<String, Object>();
	
	public ClientSession() {	
	}
	
	public void updateSession(RequestHeaders header){
		this.lastAccessIntf = header.getClazzName();
		this.lastAccessMethod = header.getMethodName();
		this.lastAccessTime = Calendar.getInstance().getTime();
		this.lastAgent = header.getAgent();
		this.lastAPIVersion = header.getApiVersion();
		this.lastDataFormat = header.getDataFormat();		
	}
	
	public ClientSession(String sessionId) {
		this.sessionId = sessionId;
	}
	
	public String getSessionId() {
		return this.sessionId;
	}
	
	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
	
	public String getLastAgent() {
		return this.lastAgent;
	}

	public void setLastAgent(String lastAgent) {
		this.lastAgent = lastAgent;
	}

	public String getLastAPIVersion() {
		return this.lastAPIVersion;
	}

	public void setLastAPIVersion(String lastAPIVersion) {
		this.lastAPIVersion = lastAPIVersion;
	}

	public Date getLastAccessTime() {
		return this.lastAccessTime;
	}
	
	public void setLastAccessTime(Date lastAccessTime) {
		this.lastAccessTime = lastAccessTime;
	}
	
	public String getLastAccessIntf() {
		return this.lastAccessIntf;
	}
	
	public void setLastAccessIntf(String lastAccessIntf) {
		this.lastAccessIntf = lastAccessIntf;
	}
	
	public String getLastAccessMethod() {
		return this.lastAccessMethod;
	}
	
	public void setLastAccessMethod(String lastAccessMethod) {
		this.lastAccessMethod = lastAccessMethod;
	}
	
	public String getLastClientIP() {
		return this.lastClientIP;
	}
	
	public void setLastClientIP(String clientIP) {
		this.lastClientIP = clientIP;
	}
	
	public String getLastDataFormat() {
		return this.lastDataFormat;
	}

	public void setLastDataFormat(String lastDateFormat) {
		this.lastDataFormat = lastDateFormat;
	}

	@SuppressWarnings("unchecked")
	public <T> T getProperty(String key) {
		T value = (T) this.map.get(key);
		return value;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T putProperty(String key, T value) {
		return (T) this.map.put(key, value);
	}
}
